package zong.Listener;

import javax.swing.*;
import java.awt.*;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;


public class MyFrame3 extends JFrame implements KeyListener {

    public MyFrame3() {

        this.setSize(500, 500);
        this.setTitle("事件演示");
        this.setAlwaysOnTop(true);
        this.setLocationRelativeTo(null);
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        this.setLayout(null);


        //创建按钮对象


        this.addKeyListener(this);


        this.setVisible(true);

    }
        @Override
        public void keyTyped (KeyEvent e){

        }

        @Override
        public void keyPressed (KeyEvent e){
            System.out.println("按下不松");
        }

        @Override
        public void keyReleased (KeyEvent e){;
            System.out.println("松开按键");
            int code=e.getKeyCode();
            System.out.println(code);
        }


    }